#include <iostream>
#include <string>

using namespace std;

// 左闭右闭
void reverse(string& s, int left, int right) {
    while (left < right) {
        char temp = s[left];
        s[left++] = s[right];
        s[right--] = temp;
    }
}

// 解题思路
// 1.整体反转
// 2.前 n 个字符反转
// 3.后 len - n 个字符反转
void rotateString(string& str, int n) {
    reverse(str, 0, str.size() - 1);
    reverse(str, 0, n - 1);
    reverse(str, n, str.size() - 1);
}

int main() {
    while (true) {
        cout << "-------------------------------";
        cout << "Enter a integer: \n";
        int num{};
        cin >> num;

        cout << "Enter a string: \n";
        string str;
        getline(cin >> ws, str);

        rotateString(str, num);

        cout << "result: \n";
        cout << str << "\n";
    }

    return 0;
}